home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 2004 #2
/
Amiga Plus CD - 2004 - No. 02.iso
/
AmiSoft
/
Util
/
conv
/
MIDI2asm.lha
/
MIDI2asm
/
MIDI2asm.rexx
< prev
Wrap
OS/2 REXX Batch file
|
2004-01-14
|
4KB
|
171 lines
/* $VER: MIDI2asm 1.1 $
* Convert MIDI data to 68k assembler source
* © by Stefan Haubenthal 1998/99/2003/04 */
if ~open(midi,arg(1)) then exit 0*writeln(stdout,"Usage: MIDI2asm midifile")
do i=0 to 11
melo.i=word("c db d eb e f gb g ab a bb b",i+1)
bass.i=word("C Db D Eb E F Gb G Ab A Bb B",i+1)
end
meta.00="seqnum"
meta.01="text"
meta.02="copyright"
meta.03="sname"
meta.04="iname"
meta.05="lyric"
meta.06="marker"
meta.07="cue"
meta.20="cprefix"
meta.21="pprefix"
meta.2F="trackend"
meta.51="tempo"
meta.54="smpte"
meta.58="time"
meta.59="key"
meta.74="seqspec"
ID.40="Kawai"
ID.41="Roland"
ID.42="Korg"
ID.43="Yamaha"
ID.44="Casio"
ID.46="Kamiya"
ID.47="Akai"
ID.48="JapanVictor"
ID.49="Mesosha"
say ";" arg(1) "V"word(sourceline(1),4)
say
say "SIZE macro"
say " dc.b \1>>24&$ff"
say " dc.b \1>>16&$ff"
say " dc.b \1>>8&$ff"
say " dc.b \1&$ff"
say " endm"
say "DELTA macro"
say " ifgt \1-16383"
say " dc.b \1>>14|128"
say " endc"
say " ifgt \1-127"
say " dc.b \1>>7&$ff|128"
say " endc"
say " dc.b \1&127"
say " endm"
say "noteoff =$80"
say "noteon =$90"
say "polypress =$A0"
say "ctrl =$B0"
say "prog =$C0"
say "chanpress =$D0"
say "pitchbend =$E0"
say "sysex =$F0"
say "meta =$FF"
say "seqnum =$00" /* sequence_number */
say "text =$01" /* text_event */
say "copyright =$02" /* copyright_notice */
say "sname =$03" /* sequence_name */
say "iname =$04" /* instrument_name */
say "lyric =$05" /* lyric */
say "marker =$06" /* marker */
say "cue =$07" /* cue_point */
say "cprefix =$20" /* channel_prefix */
say "pprefix =$21" /* port_prefix */
say "trackend =$2F" /* end_of_track */
say "tempo =$51" /* set_tempo */
say "smpte =$54" /* smpte_offset */
say "time =$58" /* time_signature */
say "key =$59" /* key_signature */
say "seqspec =$74" /* sequencer_specific */
do i=12 to 107
say centre(note(i)"=",4)i
end
say
say " data"
say ' dc.b "'readch(midi,4)'"'
say " dc.l "c2d(readch(midi,4))
say " dc.w "c2d(readch(midi,2)) "format"
tracks=c2d(readch(midi,2))
say " dc.w "tracks "tracks"
tempo=c2d(readch(midi,2))*4
say " dc.w "tempo/4 "tempo"
do track=1 to tracks
say
say "; track" track
say ' dc.b "'readch(midi,4)'"'
len=c2d(readch(midi,4))
/*say " dc.l "len "size"*/
parse value d2x(len,8) with len1 3 len2 5 len3 7 len4
say " SIZE $"len1||len2||len3||len4
time=0
measure=0
do forever
data=c2d(readch(midi))
if data<128 then delta=data
else do
delta=(data-128)*128
data=c2d(readch(midi))
if data<128 then delta=delta+data
else delta=delta*128+(data-128)*128+c2d(readch(midi))
end
time=time+delta
if time/tempo>=measure then do
say "; measure" trunc(time/tempo)+1
measure=measure+1
end
say " DELTA "delta
data=c2x(readch(midi))
select
when data<"80" then /* running status */
say " dc.b "x2d(data)","c2d(readch(midi))
when left(data,1)="8" then
say " dc.b noteoff+"x2d(right(data,1))","note(c2d(readch(midi)))","c2d(readch(midi))
when left(data,1)="9" then
say " dc.b noteon+"x2d(right(data,1))","note(c2d(readch(midi)))","c2d(readch(midi))
when left(data,1)="A" then
say " dc.b polypress+"x2d(right(data,1))","c2d(readch(midi))","c2d(readch(midi))
when left(data,1)="B" then
say " dc.b ctrl+"x2d(right(data,1))","c2d(readch(midi))","c2d(readch(midi))
when left(data,1)="C" then
say " dc.b prog+"x2d(right(data,1))","c2d(readch(midi))
when left(data,1)="D" then
say " dc.b chanpress+"x2d(right(data,1))","c2d(readch(midi))
when left(data,1)="E" then
say " dc.b pitchbend+"x2d(right(data,1))","c2d(readch(midi))","c2d(readch(midi))
when data="F0" then do /* system exclusive */
len=c2d(readch(midi))
say " dc.b sysex,"len
call dump
end
when data="FF" then do /* meta data */
data=c2x(readch(midi))
len=c2d(readch(midi))
say " dc.b meta,"meta.data","len
select
when left(data,1)="0" then
if len>1 then say ' dc.b "'readch(midi,len)'"'
else call dump
when data="2F" then leave
otherwise call dump
end
end
end
end
end
exit
dump:
d=""
do i=1 to len
d=d"$"c2x(readch(midi))
if i//8=0 | i=len then do
say " dc.b "d
d=""
end
else d=d","
end
return
note:
o=arg(1)%12
if o>=4 then return value("melo."arg(1)//12)o-4
else return value("bass."arg(1)//12)3-o